package cn.wolfcode.shop;

import cn.wolfcode.shop.domain.SkuPropertyValue;
import cn.wolfcode.shop.service.ISkuPropertyValueService;
import cn.wolfcode.shop.vo.JSONResultVo;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class SkuPropertyValueController {
    @Reference
    private ISkuPropertyValueService skuPropertyValueService;

    @RequestMapping("/skuPropertyValue/get/{skuPropertyId}")
    public String skuPropertyValueList(@PathVariable("skuPropertyId") Long skuPropertyId, Model model){
        model.addAttribute("skuPropertyValueList", skuPropertyValueService.selectByPId(skuPropertyId));
        return "skuProperty/skuProperty_value_list";
    }

    @RequestMapping("/skuPropertyValue/save")
    @ResponseBody
    public JSONResultVo saveOrUpdate(@RequestBody List<SkuPropertyValue> skuPropertyValues){
        JSONResultVo vo = new JSONResultVo();
        try {
            skuPropertyValueService.saveOrUpdate(skuPropertyValues);
        } catch (Exception e){
            e.printStackTrace();
            vo.setErrorMsg(e.getMessage());
        }
        return vo;
    }

    @RequestMapping("/skuPropertyValue/delete/{id}")
    @ResponseBody
    public JSONResultVo delete(@PathVariable("id") Long id){
        JSONResultVo vo = new JSONResultVo();
        try {
            skuPropertyValueService.delete(id);
        } catch (Exception e){
            e.printStackTrace();
            vo.setErrorMsg(e.getMessage());
        }
        return vo;
    }
}
